﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace myMoney
{
    public partial class Login : QT.Windows.Shell.GlassForm
    {
        public Login()
        {
            InitializeComponent();
            loadForm();
        }

        #region Event

        #region Button

        private void btnLogin_Click(object sender, EventArgs e)
        {
            switch (MoneyClass.User.Login(this.cbbUserID.SelectedValue.ToString(), this.cbbUserID.GetItemText(this.cbbUserID.SelectedItem), QT.Tools.MD5(this.tbPassword.Text)))
            {
                case 0:
                    MessageBox.Show("用户不存在");
                    return;
                case -1:
                    MessageBox.Show("用户名错误");
                    return;
                case -2:
                    MessageBox.Show("密码错误");
                    return;
                case 99:
                    MessageBox.Show("内部错误，请联系系统管理员");
                    return;
                default:
                    Main.CurrentGuid = this.cbbUserID.SelectedValue.ToString();
                    Main.CurrentUser = this.cbbUserID.GetItemText(this.cbbUserID.SelectedItem);
                    break;
            }

            this.tbPassword.Text = "";
            Main myApp=new Main();
            myApp.Owner = this;
            myApp.Show();
            this.Hide();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion

        #endregion

        #region Method

        private void loadForm()
        {
            DataTable dt = MoneyClass.User.getUsing();
            this.cbbUserID.DisplayMember = "userid";
            this.cbbUserID.ValueMember = "guid";
            this.cbbUserID.DataSource = dt;
        }

        #endregion
    }
}
